<#assign base=request.contextPath />
<!DOCTYPE html>
<div class="row">
	<div class="col-md-12 col-sm-12 col-xs-12">
		<div class="x_panel">
			<div class="x_title">
				<h2>资讯编辑 <small></small></h2>
				<div class="clearfix"></div>
			</div>
			<div class="x_content">
				<br/>
				<form id="postForm" data-parsley-validate class="form-horizontal form-label-left" method="post" action="${base}/gx/infoContent/save">
					<input type="hidden" id="id" name="id" value="${((obj.id)?c)!0 }">
		            <input type="hidden" name="createTime" value="${(obj.createTime)!.now?string['yyyy-MM-dd HH:mm:ss']}">
		            <input type="hidden" name="updateTime" value="${.now?string['yyyy-MM-dd HH:mm:ss']}">
		            <input type="hidden" name="creator" value="${(obj.creator)!admin.userName}">
		            <input type="hidden" name="updator" value="${(obj.updator)!admin.userName}">
		            <input type="hidden" name="isDelete" value="${((obj.isDelete)?c)!0 }">
		            <input type="hidden" name="clickNum" value="${((obj.clickNum)?c)!0 }">
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">资讯标题 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<input type="text" id="infoTitle" name="infoTitle" value="${(obj.infoTitle)!''}" class="form-control col-md-7 col-xs-12">
                        </div>
					</div>
					<#if obj??>
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">资讯分类 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<select id="classifyId" name="classifyId" class="form-control select2">
                        		<option value="">请选择</option>
	                        	<#list listParent as parent>
	                        	<option value="${parent.id?c}" <#if (obj.classifyId==parent.id)>selected="selected"</#if>>${parent.name}</option>
	                        	</#list>
	                    	</select>
                        </div>
					</div>
					<#else>
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">资讯分类 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<select id="classifyId" name="classifyId" class="form-control select2">
                        		<option value="">请选择</option>
	                        	<#list listParent as parent>
	                        	<option value="${parent.id?c}">${parent.name}</option>
	                        	</#list>
	                    	</select>
                        </div>
					</div>
					</#if>
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">资讯封面图 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<input type="file" id="icon_dropify" name="file" class="dropify" data-default-file="${imagePath}${(obj.infoIcon)!''}" data-max-file-size="1M"/>
                            <input type="hidden" name="infoIcon" id="infoIcon" value="${(obj.infoIcon)!''}">
                            <input type="hidden" name="infoIconOld" id="infoIconOld" value="${(obj.infoIcon)!''}">
                        </div>
					</div>
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">资讯简介 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<input type="text" id="infoRemark" name="infoRemark" value="${(obj.infoRemark)!''}" class="form-control col-md-7 col-xs-12">
                        </div>
					</div>
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">资讯描述 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<input type="text" id="infoDesc" name="infoDesc" value="${(obj.infoDesc)!''}" class="form-control col-md-7 col-xs-12">
                        </div>
					</div>
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">资讯内容 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	
                        	<div id="content_summernote" class="summernote" >
                                        ${(obj.infoContents)!''}
                        	</div>
                            <input type="hidden" name="infoContents" id="infoContents">
              
                        </div>
					</div>
					
					<div>123123</div>
					
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">资讯关键字 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<input type="text" id="infoKey" name="infoKey" value="${(obj.infoKey)!''}" class="form-control col-md-7 col-xs-12">
                        </div>
					</div>
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">资讯作者 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<input type="text" id="infoAuthor" name="infoAuthor" value="${(obj.infoAuthor)!''}" class="form-control col-md-7 col-xs-12">
                        </div>
					</div>
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">资讯来源 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<input type="text" id="infoSource" name="infoSource" value="${(obj.infoSource)!''}" class="form-control col-md-7 col-xs-12">
                        </div>
					</div>
					<div class="ln_solid"></div>
					<div class="form-group">
						<div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3">
							<button type="button" class="btn btn-success" id="submit">保存</button>
							<button type="button" class="btn btn-primary" id="goBack">返回</button>
						</div>
					</div>
				</form>
			</div>
		</div>
	</div>
</div>

<script type="text/javascript">
$(function() {
	//select2
	$(".select2").select2({width: "100%"});
	$('.summernote').summernote({
        height: 350, // set editor height
        minHeight: null, // set minimum height of editor
        maxHeight: null, // set maximum height of editor
        focus: false, // set focus to editable area after initializing summernote
        lang: 'zh-CN',
        shortcuts:false, //禁止使用快捷键
          toolbar: [
    // [groupName, [list of button]]
    ['style', ['bold', 'italic', 'underline', 'clear']],
    ['font', ['strikethrough', 'superscript', 'subscript']],
    ['fontsize', ['fontsize']],
    ['color', ['color']],
    ['para', ['ul', 'ol', 'paragraph']],
    ['height', ['height']]
  ]
    });
	 $('.dropify').dropify({
     	messages: {
		        'default': '点击或拖拽文件到这里',
		        'replace': '点击或拖拽文件到这里来替换文件',
		        'remove':  '移除文件',
		        'error':   '对不起，你上传的文件太大了',
		    }
     });
     // Used events
     drEvent = $('#icon_dropify').dropify();
     drEvent.on('dropify.afterClear', function(event, element) {
     	$("#infoIcon").val("");
     });

     drEvent.on('dropify.errors', function(event, element) {
         console.log('Has Errors');
     });

	$("#goBack").click(function() {
		$("#main_content").load('${base}/gx/infoContent/list');	        
    });
	
	$("#submit").click(function() {
	
		var infoTitle = $.trim($("#infoTitle").val());
		var classifyId = $.trim($("#classifyId").val());
		var infoRemark = $.trim($("#infoRemark").val());
		var infoDesc = $.trim($("#infoDesc").val());
		var infoKey = $.trim($("#infoKey").val());
		var infoAuthor = $.trim($("#infoAuthor").val());
		var infoSource = $.trim($("#infoSource").val());
    	if(infoTitle==""){
    		swal("请输入资讯标题");
            return;
    	}
    	if(classifyId==""){
    		swal("请选择分类");
            return;
    	}
    	//获取数据
		drEvent = $('.dropify').dropify();
	    drEvent=drEvent.data('dropify')
	    if((drEvent.file.object !=null )){
	    	var infoIcon = drEvent.callBackBase64;
	    	infoIcon = infoIcon.substring(infoIcon.indexOf("base64")+7);
	    	$("#infoIcon").val(infoIcon);
	    }else{
	    	if($("#infoIcon").val()==""){
	    		swal("请上传资讯封面图");
	            return;
	    	}
	    }
    	if(infoRemark==""){
    		swal("请输入资讯简介");
            return;
    	}
    	if(infoDesc==""){
    		swal("请输入资讯描述");
            return;
    	}
    	var markupStr = $('#content_summernote').summernote('code');
    	markupStr=filterhtml(markupStr);
		$("#infoContents").val(markupStr);
		alert(markupStr)
		var infoContents = $.trim($("#infoContents").val());
    	if(infoContents==""){
    		swal("请输入资讯内容");
            return;
    	}
    	if(infoKey==""){
    		swal("请输入资讯关键字");
            return;
    	}
    	if(infoAuthor==""){
    		swal("请输入资讯作者");
            return;
    	}
    	if(infoSource==""){
    		swal("请输入资讯来源");
            return;
    	}
//        var url = "${base}/gx/infoContent/save";
//         $.post(url, $("#postForm").serialize(), function(data) {
//             if (data.flag) {
//             	swal(data.msg, "", "success");
//                 $("#main_content").load('${base}/gx/infoContent/list');
//             }else{
//             	swal(data.msg, "", "error");
//             }
//         });
        $("#postForm").ajaxSubmit(function(data) {
    	 	if (data.flag) {
    	 		swal(data.msg, "", "success");
				$("#main_content").load('${base}/gx/infoContent/list');
    	 	} 
    	 	else {
    	 		swal(data.msg, "", "error");
    	 	}
    	});
	});
});
//去除页面标签参数
function filterhtml(msg) {
        var msg = msg.replace(/<\/?[^>]*>/g, ''); //去除HTML Tag
        msg = msg.replace(/[|]*\n/, '') //去除行尾空格
        msg = msg.replace(/&nbsp;/ig, ''); //去掉npsp
        return msg;
}
</script>